package skill

import (
	"gddgame.cc/galaxy/common/dsl/game"
	"gddgame.cc/galaxy/common/dsl/game/attr"
	"gddgame.cc/galaxy/utils"
)

//go:generate msgp

//msgp:tuple Buff
type Buff struct {
	Id            int                  `json:"id" msg:"id"`
	Effect        string               `json:"effect" msg:"effect"`
	IntervalTime  int                  `json:"intervalTime" msg:"intervalTime"`
	SustainedTime int                  `json:"sustainedTime" msg:"sustainedTime"`
	Overlying     bool                 `json:"overlying" msg:"overlying"`
	AttrEffect    attr.AttrEffectSlice `json:"attrEffect" msg:"attrEffect"`
	AttrEvent     [][]attr.AttrEvent   `json:"attrEvent" msg:"attrEvent"`
	CasterAttr    attr.AttrEffectSlice `json:"casterAttr" msg:"casterAttr"`
	TargetAttr    attr.AttrEffectSlice `json:"targetAttr" msg:"targetAttr"`
	Define        int                  `json:"define" msg:"group"`
	DefineLevel   int                  `json:"define_level" msg:"level"`
	Group         []int                `json:"group" msg:"group"`
	IsDeathClear  bool                 `json:"isDeathClear" msg:"isDeathClear"`
	IsSave        bool                 `json:"isSave" msg:"isSave"`

	*game.DataExtend `json:"-" msg:"-"`
	Attr             game.IntAbilityMap `json:"-" msg:"-"`
}

func NewBuff(provider *game.DataProvider, buff *SettingBuff) *Buff {
	ext := &Buff{
		Id:            buff.Id,
		Effect:        buff.Effect,
		IntervalTime:  buff.IntervalTime,
		SustainedTime: buff.SustainedTime,
		Overlying:     buff.Overlying,
		AttrEffect:    buff.AttrEffect,
		AttrEvent:     buff.AttrEvent,
		CasterAttr:    buff.CasterAttr,
		TargetAttr:    buff.TargetAttr,
		Define:        buff.Define,
		DefineLevel:   buff.DefineLevel,
		Group:         buff.Group,

		DataExtend: game.NewDataExtend(utils.ToString(buff.Id), buff.UpdateTime),

		Attr: buff.AttrEffect.GenerateAttrWithInt().ListToMap(),
	}
	return ext
}

//msgp:tuple Skill
type Skill struct {
	Id             int                  `json:"id" msg:"id"`
	Effect         string               `json:"effect" msg:"effect"`
	Distance       int                  `json:"distance" msg:"distance"`
	Radius         int                  `json:"radius" msg:"radius"`
	Speed          int                  `json:"speed" msg:"speed"`
	Angle          int                  `json:"angle" msg:"angle"`
	Number         int                  `json:"number" msg:"number"`
	Ease           int                  `json:"ease" msg:"ease"`
	ReadyTime      float32              `json:"readyTime" msg:"readyTime"`
	CastTime       float32              `json:"castTime" msg:"castTime"`
	CoolTime       float32              `json:"coolTime" msg:"coolTime"`
	IntervalTime   float32              `json:"intervalTime" msg:"intervalTime"`
	SustainedTime  float32              `json:"sustainedTime" msg:"sustainedTime"`
	HandleType     int                  `json:"handleType" msg:"handleType"`
	TargetRelation int                  `json:"targetRelation" msg:"targetRelation"`
	TargetStatus   int                  `json:"targetStatus" msg:"targetStatus"`
	CastNeed       int                  `json:"castNeed" msg:"castNeed"`
	SkillPlan      int                  `json:"skillPlan" msg:"skillPlan"`
	CastType       int                  `json:"castType" msg:"castType"`
	CallId         int                  `json:"callId" msg:"callId"`
	CallNumber     int                  `json:"callNumber" msg:"callNumber"`
	AttrEvent      [][]attr.AttrEvent   `json:"attrEvent" msg:"attrEvent"`
	CasterAttr     attr.AttrEffectSlice `json:"casterAttr" msg:"casterAttr"`
	TargetAttr     attr.AttrEffectSlice `json:"targetAttr" msg:"targetAttr"`

	*game.DataExtend `json:"-" msg:"-"`
}

func NewSkill(provider *game.DataProvider, skill *SettingSkill) *Skill {
	ext := &Skill{
		Id:             skill.Id,
		Effect:         skill.Effect,
		Distance:       skill.Distance,
		Radius:         skill.Radius,
		Speed:          skill.Speed,
		Angle:          skill.Angle,
		Number:         skill.Number,
		Ease:           skill.Ease,
		ReadyTime:      skill.ReadyTime,
		CastTime:       skill.CastTime,
		CoolTime:       skill.CoolTime,
		IntervalTime:   skill.IntervalTime,
		SustainedTime:  skill.SustainedTime,
		HandleType:     skill.HandleType,
		TargetRelation: skill.TargetRelation,
		CastNeed:       skill.CastNeed,
		SkillPlan:      skill.SkillPlan,
		CastType:       skill.CastType,
		CallId:         skill.CallId,
		CallNumber:     skill.CallNumber,
		AttrEvent:      skill.AttrEvent,
		CasterAttr:     skill.CasterAttr,
		TargetAttr:     skill.TargetAttr,

		DataExtend: game.NewDataExtend(utils.ToString(skill.Id), skill.UpdateTime),
	}
	return ext
}
